package com.block.datapush.service.apipush.utils;

import cn.hutool.core.util.StrUtil;
import com.block.common.enums.BaseTypeInfoEnum;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Objects;
import java.util.Random;

/**
 * 即速贷
 */
public class YunWeiRongiUtil {
    private static final String CHARSET_NAME = "UTF-8";



    public static Integer getGjj(String gongjijin) {
        if (StrUtil.equals(BaseTypeInfoEnum.Gjj.gjj001.getValue(), gongjijin)) {
            return 4;
        }
        return 2;
    }


    public static Integer getCar(String car) {
        if (StrUtil.equals(BaseTypeInfoEnum.Car.car001.getValue(), car)) {
            return 2;
        }
        return 1;
    }


    public static Integer getHouse(String house) {
        if (StrUtil.equals(BaseTypeInfoEnum.House.hu001.getValue(), house)) {
            return 2;
        }
        return 1;
    }

    public static Integer getyuqi(String yuqi) {
        if (StrUtil.equals(BaseTypeInfoEnum.Yuqi.yq001.getValue(), yuqi)) {
            return 1;
        }
        return 2;
    }

    public static Integer getxueli(String xueli) {
         if (StrUtil.equals(BaseTypeInfoEnum.XueLi.xl002.getValue(), xueli)) {
            return 3;
        }if (StrUtil.equals(BaseTypeInfoEnum.XueLi.xl003.getValue(), xueli)) {
            return 4;
        }if (StrUtil.equals(BaseTypeInfoEnum.XueLi.xl004.getValue(), xueli)) {
            return 5;
        }
        return 6;
    }

    public static Integer getjob(String job) {
        if (StrUtil.equals(BaseTypeInfoEnum.Gongzuo.gz001.getValue(), job)) {
            return 1;
        } else if (StrUtil.equals(BaseTypeInfoEnum.Gongzuo.gz002.getValue(), job)) {
            return 3;
        } else if (StrUtil.equals(BaseTypeInfoEnum.Gongzuo.gz004.getValue(), job)) {
            return 4;
        }
        return 2;
    }

    public static Integer getxinyongka(String xinyongka) {
        if (StrUtil.equals(BaseTypeInfoEnum.XinYongKa.xyk001.getValue(), xinyongka)) {
            return 1;
        }
        return 2;
    }


    public static Integer getbaodan(String baodan) {
        if (StrUtil.equals(BaseTypeInfoEnum.Baoxian.bx001.getValue(), baodan)) {
            return 3;
        }
        return 1;
    }



    public static Integer getloantime(String loantime) {
        if (StrUtil.equals(BaseTypeInfoEnum.LoanTime.lt001.getValue(), loantime)) {
            return 2;
        } else if (StrUtil.equals(BaseTypeInfoEnum.LoanTime.lt002.getValue(), loantime)) {
            return 6;
        } else if (StrUtil.equals(BaseTypeInfoEnum.LoanTime.lt003.getValue(), loantime)) {
            return 12;
        }
        return 2;

    }

    public static Integer getYongtu(String yongtu) {
        if (StrUtil.equals(BaseTypeInfoEnum.Yongtu.yt001.getValue(), yongtu)) {
            return 1;
        } else if (StrUtil.equals(BaseTypeInfoEnum.Yongtu.yt004.getValue(), yongtu)) {
            return 2;
        } else if (StrUtil.equals(BaseTypeInfoEnum.Yongtu.yt005.getValue(), yongtu)) {
            return 4;
        }
        return 7;
    }

    public static Integer getShouRu(String shouru) {
        if (StrUtil.equals(BaseTypeInfoEnum.Shouru.sr001.getValue(), shouru)) {
            return 5000;
        } else if (StrUtil.equals(BaseTypeInfoEnum.Shouru.sr002.getValue(), shouru)) {
            return 10000;
        } else if (StrUtil.equals(BaseTypeInfoEnum.Shouru.sr003.getValue(), shouru)) {
            return 20000;
        } else if (StrUtil.equals(BaseTypeInfoEnum.Shouru.sr004.getValue(), shouru)) {
            return 25000;
        }
        return 30000;
    }


    public static Integer getZhimaScore(String zhima) {
        if (StrUtil.equals(BaseTypeInfoEnum.Zhima.zm005.getValue(), zhima)) {
            return 3;
        } else if (StrUtil.equals(BaseTypeInfoEnum.Zhima.zm004.getValue(), zhima)) {
            return 2;
        } else if (StrUtil.equals(BaseTypeInfoEnum.Zhima.zm003.getValue(), zhima)) {
            return 1;
        }else if(StrUtil.equals(BaseTypeInfoEnum.Zhima.zm002.getValue(), zhima)){
            return 5;
        }
        return 4;
    }

    public static Integer getShebao(String shebao) {
        if(StrUtil.equals(BaseTypeInfoEnum.Shebao.sb001.getValue(), shebao)){
            return 4;
        }
        return 2;
    }


    public static String encrypt(String str, String key) {
        try {
            byte[] raw = key.getBytes(StandardCharsets.UTF_8);
            SecretKeySpec secretKeySpec = new SecretKeySpec(raw, "AES");
            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
            cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
            byte[] encrypted =cipher.doFinal(str.getBytes(StandardCharsets.UTF_8));
            return Base64.getEncoder().encodeToString(encrypted);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static String decrypt(String str, String key) {
        try {
            byte[] raw = key.getBytes(StandardCharsets.UTF_8);
            SecretKeySpec secretKeySpec = new SecretKeySpec(raw, "AES");
            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
            cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
            byte[] encrypted = cipher.doFinal(Base64.getDecoder().decode(str));
            return new String(encrypted);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }



    public static Integer getloanmount(String loanTime) {
        if(StrUtil.equals(BaseTypeInfoEnum.LoanAmount.la001.getValue(), loanTime)){
            return 1;
        }else if(StrUtil.equals(BaseTypeInfoEnum.LoanAmount.la002.getValue(), loanTime)){
            return 2;
        }else if(StrUtil.equals(BaseTypeInfoEnum.LoanAmount.la003.getValue(), loanTime)){
            return 3;
        }
        return 4;

    }
}
